/**
* @Description : _datePicker.js
* @Author : Tomi
* @Email : lintaoming@qq.com
* @Create : 2017/8/31
*/
(function($, window, undefined){
    'use strict';
    $(window.document).ready(function () {
        $('[dy8-unit="date"],[dy8-unit="daterange"]').each(function(i,e){
            var $e = $(e);

            var locale = {
                "format": $e.data('format') ? $e.data('format') : 'YYYY/MM/DD',
                "separator": " - ",
                "applyLabel": "确定",
                "cancelLabel": "取消",
                "fromLabel": "起始时间",
                "toLabel": "结束时间'",
                "customRangeLabel": "自定义",
                "weekLabel": "W",
                "daysOfWeek": ["日", "一", "二", "三", "四", "五", "六"],
                "monthNames": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                "firstDay": 1
            };

            var options = {
                locale: locale,
                singleDatePicker: true
            };

            if($e.attr('dy8-unit')=='date'){
                options.singleDatePicker = true;
            }else if($e.attr('dy8-unit')=='daterange'){
                options.singleDatePicker = false;
            }

            if($e.data('single')==false){
                options.singleDatePicker = false;
            }
            if(parseInt($e.data('increment'))){
                options.locale.format = 'MM/DD/YYYY h:mm A';
                $.extend(options, {
                    timePicker: true,
                    timePickerIncrement: parseInt($e.data('increment')),
                    timePicker24Hour: true
                });
            }
            if($e.data('void') == true){
                $.extend(options, {
                    autoUpdateInput: false
                });
                $e.on('apply.daterangepicker', function(ev, picker){
                    $(this).val(picker.startDate.format($(this).data('format') ? $(this).data('format') : 'YYYY/MM/DD'));
                });
            }
            $e.daterangepicker(options);
        });
    });
})(jQuery, window);